//
//  DefaultSwitchTableViewCell.swift
//  EasePods
//
//  Created by 李然 on 2024/5/21.
//

import UIKit

class DefaultSwitchTableViewCell: TableViewCell {

    override func makeUI() {
        super.makeUI()

        contentView.addSubview(titleLabel)
        contentView.addSubview(switchView)

        titleLabel.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(24.5)
            make.leading.equalToSuperview().offset(20)
            make.trailing.equalToSuperview().offset(-64)
            make.bottom.equalToSuperview().offset(-24.5)
        }

        switchView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-20)
            make.size.equalTo(CGSize(width: 56, height: 32))
            make.centerY.equalToSuperview()
        }
    }
    
    func bind(viewModel: DefaultSwitchCellViewModel) {
        viewModel.isEnabled.asDriver().drive(switchView.rx.isOn).disposed(by: cellDisposeBag)
        switchView.rx.isOn.bind(to: viewModel.switchChanged).disposed(by: cellDisposeBag)
    }
    
    lazy var titleLabel: Label = {
        let titleLabel = Label()
        titleLabel.textColor = R.color.common_3_text()
        titleLabel.numberOfLines = 0
        titleLabel.font = Fonts.systemFont(ofSize: 14)
        return titleLabel
    }()

    lazy var switchView: CustomSwitchView = {
        let switchView = CustomSwitchView()
        return switchView
    }()

}
